package br.com.view;

import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import br.com.control.Policy;
import br.com.model.ClienteBean;
import br.com.model.ServicoEquipar;
import br.com.modelo.R;

public class Logar extends Activity implements ServicoEquipar {
	private static final String NAMESPACE = "http://service.equiparAcessorios.com.br";
	private static final String SOAP_ACTION = "EquiparAcessorios";
	private static final String URL = "http://192.168.43.16:8085/equiparAcessorios/services/LogarUsuarioWebService?wsdl";
	private String METHOD_NAME = "LogarUsuario";
	ClienteBean bean = new ClienteBean();
	Policy p = new Policy();

	public void ChamaTela() {
		startActivity(new Intent(this, Central.class));
	}

	public void Limpar() {
		EditText localEditText1 = (EditText) findViewById(2131296268);
		EditText localEditText2 = (EditText) findViewById(2131296270);
		localEditText1.setText("");
		localEditText2.setText("");
	}

	public void MensagemLink() {
		AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
		localBuilder.setTitle("Solicitação de Login");
		localBuilder.setMessage("Telefone: (11) 3685-2804");
		localBuilder.setNeutralButton("Ok", null);
		localBuilder.show();
	}

	public void Sair(View paramView) {
		if (paramView.getId() == 2131296272) {
			Limpar();
			finish();
		}
	}

	public SoapPrimitive ServicoSoap(String paramString1, String paramString2) {
		SoapPrimitive localSoapPrimitive = null;
		try {
			SoapObject localSoapObject = new SoapObject(paramString1,
					paramString2);
			new PropertyInfo().type = PropertyInfo.STRING_CLASS;
			localSoapObject.addProperty("login", "emiranda");
			localSoapObject.addProperty("senha", "123");
			SoapSerializationEnvelope localSoapSerializationEnvelope = new SoapSerializationEnvelope(
					110);
			localSoapSerializationEnvelope.setOutputSoapObject(localSoapObject);
			new HttpTransportSE(
					"http://192.168.43.16:8085/equiparAcessorios/services/LogarUsuarioWebService?wsdl")
					.call("EquiparAcessorios", localSoapSerializationEnvelope);
			localSoapPrimitive = (SoapPrimitive) localSoapSerializationEnvelope
					.getResponse();
			System.out.println("Teste: " + localSoapPrimitive.toString());
			localSoapObject.addProperty("login", this.bean.getUsuario());
			localSoapObject.addProperty("senha", this.bean.getSenha());
			return localSoapPrimitive;
		} catch (Exception localException) {
			localException.printStackTrace();
			System.out.println("Error: " + localException.getMessage());
		}
		return localSoapPrimitive;
	}

	public void ValidaLogin(View paramView) {
		EditText localEditText1;
		String str1;
		String str2;
		if (paramView.getId() == 2131296273) {
			localEditText1 = (EditText) findViewById(2131296268);
			EditText localEditText2 = (EditText) findViewById(2131296270);
			str1 = localEditText1.getText().toString();
			str2 = localEditText2.getText().toString();
			if (str1.equals("") || (str2.equals("")) {
				Toast.makeText(this,
						"Por favor os campos deve ser prenchidos!!!", 1).show();
				Limpar();
			}

			
		label86: do {
			return;
			this.bean.setUsuario(str1);
			this.bean.setSenha(str2);
			System.out.println("Usuário: " + this.bean.getUsuario()
					+ " senha: " + this.bean.getSenha());
			if ((!str1.equals("eoliveira")) || (!str2.equals("123")))
				continue;
			Toast.makeText(this, "Cliente logado com sucesso!!!", 1).show();
			new Central();
			Central.USUARIO = this.bean.getUsuario();
			Limpar();
			startActivity(new Intent(this, Central.class));
			return;
		} while ((str1.equals("eoliveira")) && (str2.equals("123")));
			
		Toast.makeText(this, "Cliente inválido!!!", 1).show();
		localEditText1.requestFocus();
		Limpar();
	}

	@TargetApi(9)
	public void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		setContentView(R.layout.logar);
		this.p.StrictMode();
		((TextView) findViewById(2131296271))
				.setOnClickListener(new View.OnClickListener() {
					public void onClick(View paramView) {
						Logar.this.MensagemLink();
					}
				});
		EditText localEditText1 = (EditText) findViewById(2131296268);
		EditText localEditText2 = (EditText) findViewById(2131296270);
		String str1 = localEditText1.getText().toString();
		String str2 = localEditText2.getText().toString();
		this.bean.setUsuario(str1);
		this.bean.setSenha(str2);
		((EditText) findViewById(2131296268)).requestFocus();
		((Button) findViewById(2131296273))
				.setOnClickListener(new View.OnClickListener() {
					public void onClick(View paramView) {
						Logar.this.ValidaLogin(paramView);
					}
				});
	}
}
